#!/usr/bin/env python
# -*- coding:utf-8 -*-


from django import forms
from BBS import settings


class ArticleForm(forms.Form):
    title = forms.CharField(max_length=255,min_length=5)
    summary = forms.CharField(max_length=255,min_length=5)
    category_id = forms.IntegerField()
    head_img = forms.ImageField()
    content = forms.CharField(min_length=10)


def handle_upload_img(request, file_obj):
    upload_dir = '%s' % (settings.Imguploaddir)
    with open('%s/%s' % (upload_dir, file_obj.name), 'wb') as f:
        for chunk in file_obj.chunks():
            f.write(chunk)
    return file_obj.name

